/*************************************************************************
	> File Name: msg_queue.c
	> Author: Maureen 
	> Mail: 1437867946@qq.com 
	> Created Time: Sat 27 Mar 2021 07:22:25 PM CST
 ************************************************************************/

#include "head.h"

int create_msg_queue(key_t key) {
    int que_id;
    if ((que_id = msgget(key, IPC_CREAT | 0660)) < 0) {
        return -1;
    }
    return que_id;
}

int send_msg_to_queue(int que_id, int type) {
    struct msgbuf msg;
    msg.mtype = type;
    if (msgsnd(que_id, (void *)&msg, sizeof(msg.mtext), IPC_CREAT) < 0) {
        return -1;
    }
    return 0;
}

int recv_msg_from_queue(int que_id) {
    struct msgbuf msg;
    bzero(&msg, sizeof(msg));
    if (msgrcv(que_id, (void *)&msg, sizeof(msg.mtext), 0, IPC_NOWAIT) < 0) {
        return -1;
    }
    return msg.mtype;
}

void send_loop(int que_id, struct Config *config) {
    
}
